#include <iostream>
#include <vector>
using namespace std;
class Solution {
public:
    vector<string> wordSubsets(vector<string>& words1, vector<string>& words2) {
        int n2 = words2.size();
        vector<int> end(26);
        for (int i = 0; i < n2; ++i) {
            vector<int> help(26);
            for (char c : words2[i])
                help[c - 'a']++;
            for (int j = 0; j < 26; ++j)
                end[j] = max(end[j], help[j]);
        }
        vector<string> ans;
        for (string word : words1) {
            vector<int> help2(26);
            for (char c : word)
                help2[c - 'a']++;
            bool can = true;
            for (int i = 0; i < 26; ++i) {
                if (help2[i] < end[i]) {
                    can = false;
                    break;
                }
            }
            if (can)
                ans.push_back(word);
        }
        return ans;
    }
};
int main()
{
	return 0;
}